const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        
       tab:[
        {
          id: 1,
          title: '履约车辆',
        
        },
        {
            id: 2,
            title: '违约退车',
          
          },
          {
            id: 3,
            title: '到期退车',
          
          },
          {
            id: 4,
            title: '违约解除',
          
          },
      
      ],
      selectedTab: 0,

translateX: 0,
type:1
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
          var deviceInfo = wx.getDeviceInfo();
          console.log(deviceInfo)
          let d = app.globalData;
          this.getIndex(1);
          var open=wx.getStorageSync('open');  
          this.setData({
              //id:id,
              open:open,
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              bottom:d.bottom,
              domain:d.domain,
              imgUrl:d.imgUrl,
              platform:deviceInfo.platform
          })
    },
    goBack(e){
        const pages = getCurrentPages();
          const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
          console.log(prevPage);
          wx.navigateBack();
          //wx.navigateBack();
      },
      getIndex:function(type){
        let that = this;    
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        wx.request({
          url: app.globalData.domain+'/wechat/service/getMyTruck',
          data:{from:1,user_id:open.user_id,open_id:open.id,type},
          success:res=>{
              console.log(res)
              var d=res.data;
           
            that.setData({
                list:d.list,
                count:d.count

            })
          }
      })

    },
    onTapTab(evt) {
        let d = this.data;
       const { index } = evt.currentTarget.dataset || {};
       console.log(index);
       var tab = d.tab;
       var width = ((d.width-48)/4)*index;
       console.log(tab);
       var tabs = tab[index];
       console.log(tabs)
       var now = tabs.id;
       var type  = d.type;
       console.log(now+' '+ type);
       if(type != now){
           this.getIndex(now);
       }
       this.setData({
           type:now,
         translateX:width,  
         selectedTab: index,
       })
     },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})